package com.GUI.Lesson05;
//图片按钮
import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class JButtonDemo extends JFrame {

    public JButtonDemo(){
        //获得容器
        Container container = this.getContentPane();

        //将一个图片变成图标
        URL resource = JButtonDemo.class.getResource("tx.png");
        Icon icon = new ImageIcon(resource);

        //把图标放到按钮上
        JButton button = new JButton();
        button.setIcon(icon);
        button.setText("123");//当前文字
        button.setToolTipText("提示文字");

        //基本属性
        container.add(button);
        this.setVisible(true);
        this.setBounds(20,20,100,100);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {
        new JButtonDemo();
    }
}
